package org.example.ruoxing_admin_springboot3.utils;
import java.util.Random;
public class RandomCodeUtils {
    /**
     * 生成指定长度的随机验证码。
     * @param length 验证码的长度。
     * @return 生成的随机验证码。
     */
    public static String createRandomCode(int length) {
        if (length <= 0) {
            throw new IllegalArgumentException("长度必须大于0");
        }
        String upperCase = "ABDEFGHMNQRT";
        String lowerCase = upperCase.toLowerCase();
        String digits = "0123456789";
        String allChars = upperCase + lowerCase + digits;

        StringBuilder codeBuilder = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(allChars.length());
            codeBuilder.append(allChars.charAt(index));
        }
        return codeBuilder.toString();
    }
}
